//
//  FriendProfileFlippedView.m
//  iTweet
//
//  Created by Dang Duc Nam on 6/4/09.
//  Copyright 2009 Unitech. All rights reserved.
//

#import "FriendProfileFlippedView.h"
//#import "iTweetAppDelegate.h"
#import "User.h"
#import "WebViewController.h"

@implementation FriendProfileFlippedView
@synthesize goProfileButton;
@synthesize goFollowingButton;
@synthesize goFollowerButton;
@synthesize goStatusButton;
@synthesize goFavouriteButton;

-(void)setupUserInterface {
	CGRect buttonFrame = CGRectMake(10.0, 209.0, 234.0, 37.0);
	// create the button
	self.goProfileButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	self.goProfileButton.frame=buttonFrame;
	
	[self.goProfileButton setTitle:NSLocalizedString(@"ViewAtTwitterKey", @"") forState:UIControlStateNormal];	
	self.goProfileButton.font = [UIFont boldSystemFontOfSize:[UIFont buttonFontSize]];
	
	// Center the text on the button, considering the button's shadow
	self.goProfileButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
	self.goProfileButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
	
	[self addSubview:self.goProfileButton];
	return;
}

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) 
	{
		[self setAutoresizesSubviews:YES];
		[self setupUserInterface];
		
		// set the background color of the view to clearn
		self.backgroundColor=[UIColor clearColor];
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
	
	// get the background image for the state of the element
	// position it appropriately and draw the image
	UIImage *backgroundImage = [friendProfile imageForFriendProfileView];
	//UIImage *backgroundImage = [appDelegate getUserLargeImage:friendProfile];
	CGRect elementSymbolRectangle = CGRectMake(0,0, [backgroundImage size].width, [backgroundImage size].height);
	[backgroundImage drawInRect:elementSymbolRectangle];
	
	// all the text is drawn in white
	[[UIColor whiteColor] set];

	// draw the name
	UIFont *font = [UIFont boldSystemFontOfSize:36];
	CGSize stringSize = [friendProfile.name sizeWithFont:font];
	CGPoint point = CGPointMake((self.bounds.size.width-stringSize.width)/2,10);
	[friendProfile.name drawAtPoint:point withFont:font];
	
	float verticalStartingPoint=45;

	font = [UIFont boldSystemFontOfSize:24];
	stringSize = [friendProfile.screen_name sizeWithFont:font];
	point = CGPointMake((self.bounds.size.width-stringSize.width)/2,verticalStartingPoint);
	[[NSString stringWithFormat:@"%@",friendProfile.screen_name] drawAtPoint:point withFont:font];
	
	// draw the followings
	font = [UIFont boldSystemFontOfSize:14];
	NSString *followingString = NSLocalizedString(@"FollowingKey", nil);
	followingString = [NSString stringWithFormat: followingString, friendProfile.friends_count];
	stringSize = [followingString sizeWithFont:font];
	point = CGPointMake((self.bounds.size.width-stringSize.width)/2,verticalStartingPoint+40);
	[followingString drawAtPoint:point withFont:font];
	
	// create the Following List button
	CGRect buttonFrame = CGRectMake(point.x+stringSize.width+5, point.y, 24.0, 24.0);
	self.goFollowingButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
	self.goFollowingButton.frame=buttonFrame;
	[self.goFollowingButton addTarget:self action:@selector(jumpToFollowing:) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:self.goFollowingButton];
	
	// draw the followers
	font = [UIFont boldSystemFontOfSize:14];
	NSString *followerString = NSLocalizedString(@"FollowerKey", nil);
	followerString = [NSString stringWithFormat: followerString,friendProfile.followers_count];
	stringSize = [followerString sizeWithFont:font];
	point = CGPointMake((self.bounds.size.width-stringSize.width)/2,verticalStartingPoint+70);
	[followerString drawAtPoint:point withFont:font];
	// create the Follower List button
	buttonFrame = CGRectMake(point.x+stringSize.width+5, point.y, 24.0, 24.0);
	self.goFollowerButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
	self.goFollowerButton.frame=buttonFrame;
	[self.goFollowerButton addTarget:self action:@selector(jumpToFollower:) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:self.goFollowerButton];
	
	// draw the statuses
	font = [UIFont boldSystemFontOfSize:14];
	NSString *statusString = NSLocalizedString(@"StatusKey", nil);
	statusString = [NSString stringWithFormat: statusString,friendProfile.statuses_count];
	stringSize = [statusString sizeWithFont:font];
	point = CGPointMake((self.bounds.size.width-stringSize.width)/2,verticalStartingPoint+100);
	[statusString drawAtPoint:point withFont:font];
	// create the statuses List button
	buttonFrame = CGRectMake(point.x+stringSize.width+5, point.y, 24.0, 24.0);
	self.goStatusButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
	self.goStatusButton.frame=buttonFrame;
	[self.goStatusButton addTarget:[self viewController] action:@selector(jumpToStatus:) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:self.goStatusButton];
	
	// draw the favourites
	font = [UIFont boldSystemFontOfSize:14];
	NSString *favouriteString = NSLocalizedString(@"FavouriteKey", nil);
	favouriteString = [NSString stringWithFormat: favouriteString,friendProfile.statuses_count];
	stringSize = [favouriteString sizeWithFont:font];
	point = CGPointMake((self.bounds.size.width-stringSize.width)/2,verticalStartingPoint+130);
	[favouriteString drawAtPoint:point withFont:font];
	// create the favourites List button
	buttonFrame = CGRectMake(point.x+stringSize.width+5, point.y, 24.0, 24.0);
	self.goFavouriteButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
	self.goFavouriteButton.frame=buttonFrame;
	[self.goFavouriteButton addTarget:self action:@selector(jumpToFavourite:) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:self.goFavouriteButton];
	
	[self.goProfileButton addTarget:[self viewController] action:@selector(jumpToTwitter:) forControlEvents:UIControlEventTouchUpInside];
	
}

- (void)jumpToFollowing:(id)sender {
	NSLog(@"Following clicked");
	//TODO: Following clicked
}

- (void)jumpToFollower:(id)sender {
	NSLog(@"Follower clicked");
	//TODO: Follower clicked
}

- (void)jumpToFavourite:(id)sender {
	NSLog(@"Favourite clicked");
	//TODO: Favourite clicked
}

- (void)dealloc {
    [super dealloc];
	[goProfileButton release];
	[goFollowingButton release];
	[goFollowerButton release];
	[goStatusButton release];
	[goFavouriteButton release];
}


@end
